#ifndef MYTASK_H
#define MYTASK_H
#include <QDebug>
#include <QObject>
#include <QRunnable>
#include <QTcpSocket>
#include <QThread>
#include "myclient.h"
#include <QQueue>
#include <QWaitCondition>
#include <QMutex>
#include <QTimer>
#include "MsgDef.h"
#include "fileoperate.h"
class MyClient;

class MyTask : public QThread, public QRunnable
{
    Q_OBJECT
public:
    MyTask();
    ~MyTask();
    int SocketDescriptor;
    QTcpSocket* m_socket;
    QTcpSocket *tmpSocke;
    MyClient* m_client;
    QQueue<QString> m_qmsgQue;
    QMutex mutex;
    bool m_bIsStop;
    int m_nRowNum;
signals:
    void sig_RecMsg(int rowNum,QString msg);
    void sig_LogMsg(int socket,QString msg);
    void sig_UpdateClientNetState(int,QString);
    void sig_UpdateClientID(int,int);
    void sig_UpdateClientInitState(int,QString,QString,QString,QString,QString);
    void sig_UpdateVehQueue(int,myQueue,int);
    void sig_UpdateCurVeh(int,myVehInfo);
    void sig_InsertClient(int,QString,QString,QString,int&);
protected:
    void run();
    void CreateSocket();
private:
    time_t LastAliveTime;
    QTimer *m_timer;
    QString m_IP;
    FileOperate m_Log;
public slots:
    void SendMsg(int sockDes, QString msg);
    void Stop();
    void Start();
    void CheckAlive();
    void CheckNetState();
    void AnalyzeData();
public:
    quint64 ReadDateFromSocket(char *data, int len, int timeOut);
    void HandleInitInfo(int laneID, initInfo &init);
    void HandleVehQueueInfo(vehQueueInfo &vehQue);
    void HandleCurVehInfo(myVehInfo &curVeh);
    void HandleLogMsg(quint32 msgLen, vcrLogInfo &logInfo);
    //void InsetClientIp2Server(MyServer* server,QString ip);
};

#endif // MYTASK_H
